package cn.lcsjsxy.yxc.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(value = "/servlet6")
public class ServletTest6 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置响应行相关的API   HTTP/1.1    200/405/500/... 状态描述
        resp.setStatus(200);
        String info= "<h1>hello</h1>";
        //设置响应头相关的API
//        resp.setHeader("aaa","valuea");
//        resp.setHeader("Content-Type", "text/html");
        resp.setContentType("text/html");
//        resp.setHeader("Content-Length","1234");
        resp.setContentLength(info.getBytes().length);

        //设置响应体内容API
        //获得一个向响应体中输入文本字符输出流
        PrintWriter out = resp.getWriter();
        out.write(info);

        //获得一个向响应体中输入二进制信息的字节输出流
        ServletOutputStream outputStream = resp.getOutputStream();
    }
}
